/* static validation, used typically for form submits */
Valid = {
	check:function($area){
		var $inputs = $area.find('input[validate_on],select[validate_on],textarea[validate_on]');
		var ok = true;
		$inputs.each(function(){
			var $input = $(this);
			var issueMessage = "";
			var inputString = $input.val() || "";
			// clear issues
			Validate.removeIssue($input);
			
			var words = Validate.getWords($input);
			// check required
			if(words.match(/required/i) && inputString.length == 0){
				issueMessage = $h.listAppend(issueMessage,"required");
			}
			
			// check emails
			if(words.match(/email/i) && !Valid.email(inputString)){
				issueMessage = $h.listAppend(issueMessage,"check email");
			}
			
			// check minLength
			if(words.match(/minLength/i)){
				var min = Vw.getWordValue(words,'minLength');
				if(inputString.length < min && inputString.length != 0){
					issueMessage = $h.listAppend(issueMessage,'at least '+min+' chars');
				}
			}
			

			// !!show message
			if(issueMessage.length > 0){
				Validate.addIssue($input,issueMessage);
				ok = false;
			}
		});
		return ok;
	},
	email:function(string){
		if(string == ""){
			return true;
		} else {
			var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			return re.test(string);
		}
	},
	date:function(string){
		var string = string || "";
		var dateArray = string.split('/');
		if(dateArray.length != 3){
			return false;
		}
		if(dateArray[0].length != 2 || +dateArray[0] > 12 || +dateArray[0] == 0){ // validate month
			return false;
		}
		if(dateArray[1].length != 2 || +dateArray[1] > 31 || +dateArray[1] == 0){ // validate date
			return false;
		}
		if(dateArray[2].length != 4 || +dateArray[2] > 2050 || +dateArray[2] < 1900){ // validate date
			return false;
		}
		return true;
	}
};